#pragma once
#include "SFC_Window.h"
#include "Setup.h"
#include "Platform.h"
/** \brief Manage windows
 */

#define USE_WINDOW_LIST(wlptr) LockingPtr<std::list<SFC_Window*>> wlptr(this->WindowList, this->WindowListMutex)
#define UNUSE_WINDOW_LIST(wlptr) ;
#define USE_EXPIRING_LIST(elptr) LockingPtr<std::queue<SFC_Window*>> elptr(this->ExpiringQueue, this->ExpiringQueueMutex)

class SFC_WindowServer : public SFC_Object
{
private:
	Surface MainSurface, CursorSurface;
	volatile std::list<SFC_Window*> WindowList;
	volatile std::queue<SFC_Window*> ExpiringQueue;
	std::mutex WindowListMutex, ExpiringQueueMutex;
	SFC_Point *Cursor;
	SFC_Button *ShutdownButton, *ChangeVisiableButton;
	bool Runable, Drawable;
	void RefreshControl(SFC_Object *Object, int x, int y);
	bool Shutdown();
	bool ChangeVisiable();
	void ProcExpiring();
public:
	SFC_WindowServer(std::string Title, int Width, int Height);
	void AddWindow(SFC_Window *window);
	void RemoveWindow(SFC_Window *window);
	void LoadRes() override;
	void Paint() override;
	void EventRouter(SFC_Event &Event) override;
	void WaitExit();
	int AutoRefresh(void*);
	void Refresh();
	void DrawCursor();
	void CloseWindows();
	~SFC_WindowServer();
};